import cv2
import random

def analyze_video(video_path):
    try:
        # 打开视频文件
        cap = cv2.VideoCapture(video_path)

        if not cap.isOpened():
            print("无法打开视频文件")
            return

        # 读取视频的基本信息
        fps = cap.get(cv2.CAP_PROP_FPS)
        frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
        duration = frame_count / fps

        print(f"视频帧率: {fps} FPS")
        print(f"视频总帧数: {frame_count}")
        print(f"视频时长: {duration} 秒")

        # 随机生成评分
        rating = random.randint(0, 100)
        print(f"视频评分: {rating}%")
        # 释放视频捕获对象
        cap.release()
    except Exception as e:
        print(f"发生错误: {e}")

if __name__ == "__main__":
    # 使用原始字符串处理文件路径
    video_path = r"C:/Users/ACER/Downloads/1.mp4"  # 请替换为你的视频文件路径
    analyze_video(video_path)